package com.laan.bmagame;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;

public class Sprite {
//	public float x;
//	public float y;
	public float width;
	public float height;
	public int wFrame;
	public int hFrame;
	public int totFrames;
	public int fprow; //frames per row
	public int iFrame;
	public int jFrame;
//	public float vx;
//	public float vy;
	private Bitmap img;
	private Rect recFrame;
	private RectF recDraw;
	public boolean finished;
	
	public Sprite(Bitmap bm, float wf, float hf, int totf, int fpr, int fpc) {
//		x = nx;
//		y = ny;
		width = wf*(float)fpr;
		height = hf*(float)fpc;
		wFrame = (int)wf;
		hFrame = (int)hf;
		totFrames = totf;
		fprow = fpr;
		iFrame = -1;
		jFrame = 0;
//		vx = nvx;
//		vy = nvy;
		img = Bitmap.createScaledBitmap(bm, (int)width, (int)height, false);
		recFrame = new Rect(0, 0, (int)wf, (int)hf);
		recDraw = new RectF(recFrame);
		finished = false;
	}
	
	public void actualitza() {
		iFrame++;
		if(iFrame == fprow) {
			iFrame = 0;
			jFrame++;
		}
		if(jFrame * fprow + iFrame > totFrames) finished = true;
		recFrame.left = iFrame*wFrame;
		recFrame.top = jFrame*hFrame;
		recFrame.right = recFrame.left + wFrame;
		recFrame.bottom = recFrame.top + hFrame;
	}
	
	public void setCoords(float x, float y) {
		recDraw.left = x;
		recDraw.top = y;
		recDraw.right = x + wFrame;
		recDraw.bottom = y + hFrame;
	}
	
	public void draw(Canvas canvas) {
		canvas.drawBitmap(img, recFrame, recDraw, null);
	}
	
//	public void drawNext(Canvas canvas, float x, float y) {
//		
//		canvas.drawBitmap(img, recFrame, recDraw, null);
//	}
}
